<%@page import="servlets.AdminServlet"%>
<%@page import="java.io.FileOutputStream"%>
<%@page import="java.io.OutputStream"%>
<%@page import="java.io.InputStream"%>
<%@page import="java.io.PrintStream"%>
<%@page import="java.net.HttpURLConnection"%>
<%@page import="java.net.URL"%>
<%@page import="java.util.Enumeration"%>
<%@page import="java.util.Arrays"%>
<%@page import="java.awt.List"%>
<%@page import="java.util.Iterator"%>
<%@page import="java.lang.reflect.Array"%> 
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"  import="java.util.ArrayList, db.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html> 
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1.0, maximum-scale=1.0"/>

<!-- Icons for Web App<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<link rel="apple-touch-icon" sizes="114x114" href="images/nav/index@2x.png">
<link rel="apple-touch-startup-image" href="images/splash/splash-screen.png" media="screen and (max-device-width: 320px)" />
<link rel="apple-touch-startup-image" media="(max-device-width: 480px) and (-webkit-min-device-pixel-ratio: 2)" href="images/splash/splash-screen@2x.png" />
-->
<title>Frontera Pesos Edit Profile</title>
<link href="styles/style.css" rel="stylesheet" type="text/css">
<link href="styles/type.css" rel="stylesheet" type="text/css">
<link href="styles/buttons.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" media="only screen and (-webkit-min-device-pixel-ratio: 2)"	type="text/css" href="styles/highdpi.css" />

<!-- Load the Latest JQuery Version and Latest Validation Plugin -->
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" src="http://jzaefferer.github.com/jquery-validation/jquery.validate.js"></script>

<!-- Load script to dynamically replace images on High DPI / Retina displays -->
<script type="text/javascript" src="scripts/highdpi.js"></script>

<!-- Load custom jQuery functions-->
<script type="text/javascript" src="scripts/custom.js"></script>

<!-- Load script to check cookies -->
<script type="text/javascript" src="scripts/_cookie.js"></script>
<!-- utility js -->
<script type="text/javascript" src="../scripts/fronteraWebUtility.js"></script>
</head>
<body >


<% //DBHelper helper = new DBHelper();
	Roles roles = new Roles();   

	String _errorMessage = "";
	String _userName = "";
	String _loginID = "";
	ArrayList<UserData> userInfo =  new ArrayList<UserData>();
	int id = -1;
	int server = 0;
	int admin = 0;
	String showAdminBtn = "none";
	String showServerBtn = "none";
	Cookie[] cookies = request.getCookies();
	ArrayList<Roles> roleInfo =  new ArrayList<Roles>();
	roleInfo = roles.getRoleInfo();
	%>
	
	



<% 
if(session.getAttribute("adminRights") != null)
{
	   
	    Object g =  session.getAttribute("adminRights");
	    admin = Integer.parseInt(g.toString());
	    if(admin == 1)
		{
	    	 showAdminBtn = "inline";
		}
	   
	   
	    System.out.println(" showAdminBtn ==  " + admin);
}
	
	
   if(session.getAttribute("errorMessage") != null)
   {
	    Object g =  session.getAttribute("errorMessage");
	   _errorMessage = g.toString();
	}
   else
   {
	   _errorMessage = "";
   }
 
if(request.getParameter("itemID") != null)
{
	id = Integer.parseInt(request.getParameter("itemID"));
	if(session.getAttribute("customerInfo") != null)
	 {
	 	Object t = session.getAttribute("customerInfo");
	 	userInfo = (ArrayList<UserData>) t;
	}	
	 for(int i = 0; i < userInfo.size(); i++) {
			System.out.println(" userdata larry er " + userInfo.get(i).getPhoneNumber());
	 }
	System.out.println(" userdata larry 12 " );
}
else
{
	if(session.getAttribute("userInfo") != null)
	{
		Object t = session.getAttribute("userInfo");
		userInfo = (ArrayList<UserData>) t;
		id = userInfo.get(0).getUserID();
		 for(int i = 0; i < userInfo.size(); i++) {
				System.out.println(" userdata larry 34 " + userInfo.get(i).getPhoneNumber());
		 }
}
} 

if(session.getAttribute("serverRights") != null)
{
	   
	    Object g =  session.getAttribute("serverRights");
	    server = Integer.parseInt(g.toString());
	    if(server == 1)
		{
	    	showServerBtn = "inline";
		}
	    
	    System.out.println(" showServerBtn ==  " + server);
}
  %>

 
<div class="landing-page2">
	<p class="center-text landing-logo shadow">
	
    	<img class="replace-2x" width="300" src="../assets/frontera-pesos-logo.png" alt="img">
        <br/>
	Frontera Pesos Rewards Program!</p>

	<div class="login-box">
      <script>
function updateProfile()
{
	
	document.getElementById("pesoEditProfile").submit();
}
function goHome()
{
	var UrlLink = "userHomePage.jsp";
	window.location.href=UrlLink;
	
}

function showErrorTxt()
{
	var em = '<%=_errorMessage%>';
	if(em !="")
			{
				alert(em);
				
			}
	
}







  </script>
       <p><span style="display:<%=showAdminBtn%>">
        <a href="admin-view.jsp">Administration</a> - <a href="admin-view-customer.jsp">Customer Info</a> - 
       </span>
       <span style="display:<%=showServerBtn%>">
        <a  href="server.jsp" >Server</a> - 
        
        </span>
        
        <span>
        <a href="admin-view-faq.html">Faq</a> - <a href="userHomePage.jsp">Home</a></span>
        </p>
        <span>
        <p><a  href="javascript:void(0);" onClick="logUserOut();"><strong>Logout</strong></a><strong></strong></p>
        </span>
    <form name="pesoEditProfile" id="pesoEditProfile" action="../Admin" method="post" >
    <div id="errorTxt" class="errorMessageTxt"><%=_errorMessage %></div>
    <div id="editForm">
    <%for(int i = 0; i < userInfo.size(); i++) {
    	System.out.println(" userdata larry 90 " + userInfo.get(i).getPhoneNumber());
		 
    	if(userInfo.get(i).getUserID() == id)
    		{
    			UserData userDataList = userInfo.get(i);
    			System.out.println(" userdata larry 09 " + userInfo.get(i).getPhoneNumber());
   			 	 	
    %>
    		<input type="tel" name="phone" id="phone" placeholder="Mobile Number" value="<%=userDataList.getPhoneNumber()%>" class="text-input" />
			 <input type="password" name="password" id="password" placeholder="Password" value="<%=userDataList.getPassword()%>" class="text-input"  />
            <input type="hidden" name="adminRequestType" id="adminRequestType" value="editprofile" placeholder="adminRequestType" />
        	<input type="password" name="password" id="password" placeholder="Retype Password" value="<%=userDataList.getPassword()%>" class="text-input" />
            <input type="text" name="fullname" id="textfield" placeholder="Full Name" value="<%=userDataList.getUserFullName()%>" class="text-input" />
            <input type="email" name="email" id="username" value="<%=userDataList.getUserEmail()%>" placeholder="Email" class="text-input"  />
           <input type="text" name="birthday" id="birthday" value="<%=userDataList.getUserBirthday()%>" placeholder="mm/dd/yyyy">
    		<input type="hidden" name="custID" id="custID" value="<%=userDataList.getUserID()%>"  />
        	
        <%
        break;} 
        }%>     
	        
	          <p style="display:<%=showAdminBtn%>">
          <select name="role" id="role">
          <option value="0">Select Role</option>
           <% for(int i = 0; i < roleInfo.size(); i++) { 
     				System.out.println(" role data  "+ i);%>
            
            <option  value="<%=roleInfo.get(i).getRoleId()%>"><%=roleInfo.get(i).getRoleName()%></option>
           <%} %>
        </select></p>
            </div>
            
            <div class="clear" style="height:25px;"></div>
           
            <span class="buttonBig" id="updateProfile-button"><a href="javascript:void(0)" onClick="goHome()" class="buttonBigBlue">Back</a></span>    </form>
      
            <span class="buttonBig" id="updateProfile-button"><a href="javascript:void(0)" onClick="updateProfile()" class="buttonBigBlue">Update</a></span>    </form>
        <div class="clear"></div>
    </div>
    <div class="login-box-deco1"></div>
    <div class="login-box-deco2"></div>


<div style="height:25px;"></div>
</div>    

 
</body>
</html>